home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_bas / txtprn.zip / TXTPRN.BAS < prev   
BASIC Source File  |  1994-06-14  |  4KB  |  98 lines

  1. Sub textprint ()
  2.  
  3. 'Check for text in text box; exit if none.
  4. If Text1.Text = "" Then
  5.     msg$ = "Nothing to print."
  6.     MsgBox msg$
  7.     Exit Sub
  8. End If
  9.  
  10. 'Get font size from user (12 pt. default)...exit if Cancel
  11. prompt$ = "Enter an font size (Arial) in points. Left margin is 1.5 inches, others are 1 inch. For other formatting, load .LEC file into any word processor."
  12. setfontsize$ = InputBox(prompt$, "Prompter", "12")
  13. If setfontsize$ = "" Then Exit Sub
  14. setsize = Val(setfontsize$)
  15.  
  16. screen.MousePointer = 11 'Set hourglass pointer
  17. temp$ = Text1.Text 'Stores text box text in temporary variable
  18.  
  19. On Error Resume Next ' Reverts to defaults if font or size invalid
  20. printer.ScaleMode = 5 ' Sets printer scale mode to inches
  21. printer.FontName = "Arial" 'Sets printer font
  22. printer.FontSize = setsize 'Sets printer font size to user value.
  23. printer.CurrentY = .5 'Sets top margin for header
  24. printer.CurrentX = 1.25 'Sets left margin with allowance for printer non-printing area
  25. pageno = 1 'starts page number count for header
  26.  
  27. 'Prints header line on first page
  28. 'thefile$ is a global variable from the program this came from.
  29.  
  30. printer.Print UCase$(thefile$); "  "; Date$; " -- Page "; pageno
  31.  
  32. printer.CurrentY = 1 ' Sets top margin for actual text
  33.  
  34. 'Loop below parses temp$
  35. For x = 1 To Len(temp$)
  36.  
  37.     'Loop adds characters to print string until width too wide for margins
  38.     Do
  39.         thisline$ = thisline$ + Mid$(temp$, x, 1) 'gets single character from string
  40.         If Right$(thisline$, 1) = Chr$(10) Then ' Checks for linefeed character and sends string to printer
  41.             thisline$ = Left$(thisline$, Len(thisline$) - 2) 'removes newline character from print string
  42.             If printer.CurrentY + printer.TextHeight(thisline$) > 10 Then GoTo nextpage 'checks for bottom margin
  43.             GoTo doprint 'branches to print routine
  44.         End If
  45.         x = x + 1 'resets loop parameter
  46.     Loop Until printer.TextWidth(thisline$) > 6 'maximum line width (calculated)
  47.         
  48.         'tests for space at end of line...if not there, moves backward to find last space
  49.         If Right$(thisline$, 1) = " " Then x = x - 1 'resets loop parameter back one to compensate
  50.         If Right$(thisline$, 1) <> " " Then
  51.  
  52.             'Looks for last space in printer string
  53.             For checkchar = Len(thisline$) To 1 Step -1
  54.                 testchar$ = Mid$(thisline$, checkchar, 1)
  55.                 x = x - 1 'resets loop parameter back one to compensate
  56.                 'Found space? Exit loop
  57.                 If testchar$ = " " Then
  58.                     Exit For
  59.                 End If
  60.                 thisline$ = Left$(thisline$, Len(thisline$) - 1)
  61.             Next checkchar
  62.         End If
  63.         
  64.         'Check again for bottom margin for safety's sake before falling through to print routine
  65.         If printer.CurrentY + printer.TextHeight(thisline$) > 10 Then GoTo nextpage
  66.         
  67.         
  68. doprint:
  69.         thisline$ = Left$(thisline$, Len(thisline$)) ' trim printer string
  70.         printer.CurrentX = 1.25 'set left margin (must do for each line printed)
  71.         printer.Print thisline$ 'print the line
  72.         thisline$ = "" 'set thisline$ variable to empty
  73. Next x
  74.  
  75. printer.EndDoc 'end print job
  76. screen.MousePointer = 0 'restore mousepointer
  77. Exit Sub ' avoids falling through to nextpage label
  78.  
  79. 'Routine to jump to next page--sorry for the GoTos
  80.  
  81. nextpage:
  82. printer.NewPage
  83.  
  84. 'Reset all printer settings -- required for some printer drivers
  85. printer.ScaleMode = 5
  86. printer.FontName = "Arial"
  87. printer.FontSize = setsize
  88. printer.CurrentY = .5
  89. printer.CurrentX = 1.25
  90. pageno = pageno + 1
  91. printer.Print UCase$(thefile$); " -- Page "; pageno ' print header for new pages
  92. 'reset margins for next actual text line
  93. printer.CurrentX = 1.25
  94. printer.CurrentY = 1
  95. GoTo doprint 'return to print routine
  96.  
  97. End Sub
  98.